import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:io';

import 'app_theme.dart';
import 'home/home.dart';
import 'task/task.dart';
import 'mine/mine.dart';

void main() {
  runApp(ScaffoldRoute());
}

class MainApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: new ScaffoldRoute(),
    );
  }
}

class ScaffoldRoute extends StatefulWidget {
  @override
  _ScaffoldRouteState createState() => _ScaffoldRouteState();
}

class _ScaffoldRouteState extends State<ScaffoldRoute>
    with SingleTickerProviderStateMixin {
  //底部page controller
  int page = 0;
  List<Widget> pages = [HomePage(), TaskPage(), MinePage()];

  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      systemNavigationBarColor: AppTheme.nearlyWhite,
      statusBarColor: Colors.transparent,
      statusBarIconBrightness: Brightness.dark,
      statusBarBrightness:
          Platform.isAndroid ? Brightness.dark : Brightness.light,
      systemNavigationBarDividerColor: Colors.grey,
      systemNavigationBarIconBrightness: Brightness.dark,
    ));
    return MaterialApp(
      /*theme: ThemeData(
        primarySwatch: Colors.blue,
        textTheme: AppTheme.textTheme,
        platform: TargetPlatform.iOS,
      ),*/
      theme: ThemeData(
        highlightColor: Colors.transparent,
        splashColor: Color.fromRGBO(0, 0, 0, 0),
        primarySwatch: Colors.blue,
        primaryColor: Colors.white,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: Scaffold(
        body: pages[page],
        bottomNavigationBar: BottomNavigationBar(
          items: [
            BottomNavigationBarItem(icon: Icon(Icons.home_filled), label: '首页'),
            BottomNavigationBarItem(icon: Icon(Icons.assessment), label: '任务'),
            BottomNavigationBarItem(icon: Icon(Icons.person), label: '我的'),
          ],
          onTap: onTap,
          currentIndex: page,
          selectedItemColor: Colors.red,
          selectedFontSize: 14,
          selectedLabelStyle: TextStyle(fontWeight: FontWeight.bold),
          unselectedLabelStyle: TextStyle(),
          unselectedFontSize: 14,
        ),
      ),
    );
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  void onTap(int index) {
    setState(() {
      page = index;
    });
  }
}
